import type { ConsultType } from '@/enums'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    const consult = ref<PartialConsult>({})

    const setType = (type: ConsultType) => (consult.value.type = type)
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)
    const setDep = (depId: string) => (consult.value.depId = depId)
    const setIllneess = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }
    const setPatientId = (id: string) => (consult.value.patientId = id)
    //优惠卷函数
    const setCoupon = (id: string) => (consult.value.couponId = id)

    const clear = () => (consult.value = {})
    return { consult, setType, setIllnessType, setDep, setIllneess, setPatientId, setCoupon, clear }
  },
  { persist: true },
)
